#include <SDL/SDL.h>
#include "game.h"
#include "math.h"

int event_process(Game *g, SDL_Event *ev)
{
    while(SDL_PollEvent(ev)) {
        Uint8 *keystate = SDL_GetKeyState(NULL);

        if(keystate[SDLK_d] || keystate[SDLK_RIGHT]) {
            if(g->entity->xy_hw.x < 675) g->entity->xy_hw.x += 8;
            else g->entity->xy_hw.x = 675; 
            // SDL_BlitSurface(g->entity[1].frames[0], NULL, g->screen, &(g->entity[1].xy_hw));
            // SDL_UpdateRect(g->screen, g->entity[1].xy_hw.x, g->entity[1].xy_hw.y, g->entity[1].frames[0]->w, g->entity[1].frames[0]->h); 
        }

        if(keystate[SDLK_a] || keystate[SDLK_LEFT]) {
            if(g->entity->xy_hw.x > 25)  g->entity->xy_hw.x -= 8;
            else g->entity->xy_hw.x = 25; 
            // SDL_BlitSurface(g->entity[1].frames[0], NULL, g->screen, &(g->entity[1].xy_hw));
            // SDL_UpdateRect(g->screen, g->entity[1].xy_hw.x, g->entity[1].xy_hw.y, g->entity[1].frames[0]->w, g->entity[1].frames[0]->h); 
        }

        if(g->entity->xy_hw.x < 221 && g->entity->xy_hw.x > -1) 
            g->entity->xy_hw.y = sqrt(201 * 201 - pow(g->entity->xy_hw.x - 225, 2)) + 220;
        if(g->entity->xy_hw.x < 801 && g->entity->xy_hw.x > 475) 
            g->entity->xy_hw.y = sqrt(201 * 201 - pow(-g->entity->xy_hw.x + 475 , 2)) + 220;


        if(keystate[SDLK_SPACE]) {
            printf("Pulou\n");
        }

        if(keystate[SDLK_ESCAPE])
            quit_game(g);
    }

    return 0;
}


